//
//  RGMeVedioCell.m
//  RedGrass
//
//  Created by wukong on 2018/11/27.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMeVedioCell.h"

@interface RGMeVedioCell()

@property (nonatomic, strong) UIImageView    *imageView;
@property (nonatomic, strong) UIImageView   *playIcon;
@property (nonatomic, strong) UIButton       *favoriteNum;


@end

@implementation RGMeVedioCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self){
        self.clipsToBounds = YES;
        _imageView = [[UIImageView alloc] init];
        _imageView.backgroundColor = UICOLOR_WITH_RGBINT(0x5C5D66);
        _imageView.contentMode = UIViewContentModeScaleToFill;
        [self.contentView addSubview:_imageView];
        
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor, (__bridge id)UICOLOR_WITH_RGBINT_A(0x000000, 0.2).CGColor, (__bridge id)UICOLOR_WITH_RGBINT_A(0x000000, 0.6).CGColor];
        gradientLayer.locations = @[@0.3, @0.6, @1.0];
        gradientLayer.startPoint = CGPointMake(0.0f, 0.0f);
        gradientLayer.endPoint = CGPointMake(0.0f, 1.0f);
        gradientLayer.frame = CGRectMake(0, self.frame.size.height - 100, self.frame.size.width, 100);
        [_imageView.layer addSublayer:gradientLayer];
        
        _favoriteNum = [[UIButton alloc] init];
        [_favoriteNum setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [_favoriteNum setTitleEdgeInsets:UIEdgeInsetsMake(0, 2, 0, 0)];
        [_favoriteNum setTitle:@"0" forState:UIControlStateNormal];
        [_favoriteNum setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _favoriteNum.titleLabel.font = FONT(customFontName, 13);
        [_favoriteNum setImage:[UIImage imageNamed:@"播放量"] forState:UIControlStateNormal];
        [_favoriteNum setImageEdgeInsets:UIEdgeInsetsMake(0, -2, 0, 0)];
        [self.contentView addSubview:_favoriteNum];
        
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
        [_favoriteNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(10);
            make.bottom.right.equalTo(self.contentView).inset(10);
        }];
    }
    return self;
}

-(void)setHighlighted:(BOOL)highlighted {
    [super setHighlighted:NO];
}

- (void)prepareForReuse {
    [super prepareForReuse];
    [self.imageView setImage:nil];
}

- (void)setModel:(RGRecommendVideoModel *)model {
    [self.imageView setImageURL:[NSURL URLWithString:model.coverPath]];
   
//    [_favoriteNum setTitle:[self makeCountStrWithNumber:model.playCount] forState:UIControlStateNormal];
}

-(void) setShowCount:(NSInteger)showCount{
    _showCount = showCount;
    [_favoriteNum setTitle:[self makeCountStrWithNumber:showCount] forState:UIControlStateNormal];
}

-(void) setIsShowLikeImg:(BOOL)isShowLikeImg{
    _isShowLikeImg = isShowLikeImg;
    if(isShowLikeImg){
          [_favoriteNum setImage:[UIImage imageNamed:@"喜欢1"] forState:UIControlStateNormal];
    }else{
          [_favoriteNum setImage:[UIImage imageNamed:@"播放量"] forState:UIControlStateNormal];
    }
}

-(NSString *)makeCountStrWithNumber:(NSInteger)num{
    if(num < 10000){
        return [NSString stringWithFormat:@"%ld",num];
    }
    float tempNum = num / 10000;
    return [NSString stringWithFormat:@"%0.1fW",ceil(tempNum)];
}

@end
